package com.adb.war.fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * Fragment Activity is similar to Activity it has same life cycle of activity
 * This is Fragment activity add run time Fragment when you press button
 * Dynamically add Fragment in Activity
 * 
 */
public class War_Fragment_01Activity extends FragmentActivity implements OnClickListener{
	
	public static final String TAG = War_Fragment_01Activity.class.getCanonicalName();
	
	private Button btnWar;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnWar = (Button)findViewById(R.id.btn_war);
        btnWar.setOnClickListener(this);
        
    }
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_war:
			Log.debug(TAG,"btnWar callback");
			callIndianFragment();
			break;

		default:
			break;
		}
	}
	
	public void callIndianFragment(){
		
		FragmentManager fragmentManager = getSupportFragmentManager();
		FragmentTransaction fragmentTransaction= fragmentManager.beginTransaction();
		IndianFragment mIndian = new IndianFragment();
		//TODO First Argument is Id of ViewGroup in Activity
		//Second is Fragment object that want to add at Runtime 
		fragmentTransaction.add(R.id.fragment_container,mIndian);
		//add the transaction to the back stack
		fragmentTransaction.addToBackStack(null);
		fragmentTransaction.commit();
	}
}